//-----------------Sonic CD Door Script-------------------//
// Yeah...

// Aliases
#alias Object.Value0	:	Object.Timer
#alias Object.Value1	:	Object.YVelocity
#alias Object.Value2	:	Object.T4
#alias Object.Value3	:	Object.TimerExtra
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod


#alias Object.PropertyValue		:	PushButton.Pressed	

 
// Priority
#alias 0	:	PRIORITY_BOUNDS
#alias 1	:	PRIORITY_ACTIVE

// States
#alias 0	:	DOOR_STAND
#alias 1	:	DOOR_UP
#alias 2	:	DOOR_UP_STAND
#alias 3	:	DOOR_DOWN

sub ObjectMain
	if Object.State == DOOR_UP
		Object.Timer++
		if Object.Timer == 2
			Object.TimerExtra++
			Object.Timer = 0
			Object.YVelocity = -50000
			Object.YPos += Object.YVelocity
		end if
		if Object.TimerExtra == 84
			Object.TimerExtra = 0
			Object.YVelocity = 0
			Object.Timer = 0
			Object.State = DOOR_UP_STAND
		end if
	end if
	
	if Object.State == DOOR_DOWN
		Object.Timer++
		if Object.Timer == 2
			Object.TimerExtra++
			Object.Timer = 0
			Object.YVelocity = 50000
			Object.YPos += Object.YVelocity
		end if
		if Object.TimerExtra == 84
			Object.TimerExtra = 0
			Object.YVelocity = 0
			Object.Timer = 0
			Object.State = DOOR_STAND
		end if
	end if
	
	if	Object.State[-1] == 0
		if	Object.State == DOOR_UP_STAND
			Object.State    = DOOR_DOWN
		end if
	end if
	
			if	Object.State[-1] == 1
				if	Object.State == DOOR_STAND
					Object.State    = DOOR_UP
				end if
			end if
end sub

sub ObjectPlayerInteraction
	PlayerObjectCollision(C_BOX, -16, -32, 16, 32)
end sub

sub ObjectDraw
	DrawSprite(0)
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects2.gif")

	TempValue0 = HUD.CurrentTimePeriod
	TempValue1 = 1
	TempValue0 *= 33
	TempValue1 += TempValue0 
	SpriteFrame(-16, -32, 32, 64, TempValue1, 1)	// #0 - 100% not secret
	
	// Set this object to always active
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[Door]
			Object[ArrayPos0].Priority = PRIORITY_ACTIVE
		end if
		ArrayPos0++
	loop
end sub

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("R2/Objects2.gif")

	SpriteFrame(-16, -32, 32, 64, 1, 1)	// #0 - 100% not secret
	
	//SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")

	AddEditorVariable("state")
	SetActiveVariable("state")
	AddEnumVariable("door stand", DOOR_STAND)
	AddEnumVariable("door up", DOOR_UP)
	AddEnumVariable("door up stand", DOOR_UP_STAND)
	AddEnumVariable("door down", DOOR_DOWN)

end sub